﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefProcessDoc" :model="stateProcessDoc.vmModel" label-width="100px">
      <el-row>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_RouteId_FormItem" prop="Entity.RouteId" :label="$t('message.autotrans._Model_ProcessDoc_Route')" :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessDoc_Route')}), trigger: 'blur' }]" >
            <el-select v-model="stateProcessDoc.vmModel.Entity.RouteId" @change="onRouteChange"  clearable>
               <el-option v-for="item in stateProcessDoc.AllRoutes" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_OpId_FormItem" prop="Entity.OpId" :label="$t('message.autotrans._Model_ProcessDoc_Op')" :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessRouteItem_OpCode')}), trigger: 'blur' }]"  >
            <el-select v-model="stateProcessDoc.vmModel.Entity.OpId" clearable>
               <el-option v-for="item in stateProcessDoc.AllOps" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
<!--        <el-col :xs="24" :lg="12" class="mb20">-->
<!--        <el-form-item ref="Entity_OpCode_FormItem" prop="Entity.OpCode" :label="$t('message.autotrans._Model_ProcessDoc_OpCode')">-->
<!--            <el-input v-model="stateProcessDoc.vmModel.Entity.OpCode" clearable></el-input>-->
<!--        </el-form-item>-->

<!--        </el-col>-->
<!--        <el-col :xs="24" :lg="12" class="mb20">-->
<!--        <el-form-item ref="Entity_ProductId_FormItem" prop="Entity.ProductId" :label="$t('message.autotrans._Model_ProcessDoc_ProductId')">-->
<!--            <el-input v-model="stateProcessDoc.vmModel.Entity.ProductId" clearable></el-input>-->
<!--        </el-form-item>-->

<!--        </el-col>-->
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_FileName_FormItem" prop="Entity.FileName" :label="$t('message.autotrans._Model_ProcessDoc_FileName')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessDoc_FileName')}), trigger: 'blur' }]" >
            <el-input v-model="stateProcessDoc.vmModel.Entity.FileName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_FileType_FormItem" prop="Entity.FileType" :label="$t('message.autotrans._Model_ProcessDoc_FileType')">
            <el-input v-model="stateProcessDoc.vmModel.Entity.FileType" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_FileDocId_FormItem" prop="Entity.FileDocId" :label="$t('message.autotrans._Model_ProcessDoc_FileDoc')">
            <wtm-upload-file v-model="stateProcessDoc.vmModel.Entity.FileDocId"  @filechange="onFileChange" clearable/>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_RemotePc_FormItem" prop="Entity.RemotePc" :label="$t('message.autotrans._Model_ProcessDoc_RemotePc')">
            <el-input v-model="stateProcessDoc.vmModel.Entity.RemotePc" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_RemotePath_FormItem" prop="Entity.RemotePath" :label="$t('message.autotrans._Model_ProcessDoc_RemotePath')">
            <el-input v-model="stateProcessDoc.vmModel.Entity.RemotePath" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_UserName_FormItem" prop="Entity.UserName" :label="$t('message.autotrans._Model_ProcessDoc_UserName')">
            <el-input v-model="stateProcessDoc.vmModel.Entity.UserName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Pwd_FormItem" prop="Entity.Pwd" :label="$t('message.autotrans._Model_ProcessDoc_Pwd')">
            <el-input type="password" show-password v-model="stateProcessDoc.vmModel.Entity.Pwd" clearable></el-input>
        </el-form-item>

        </el-col>
				<el-col :xs="24" :lg="12" class="mb20">
					<el-form-item ref="Entity_Active_FormItem" prop="Entity.Active" :label="$t('message.autotrans._Model_ProcessParameter_Active')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessParameter_Active')}), trigger: 'blur' }]" >
						<el-switch v-model="stateProcessDoc.vmModel.Entity.Active" clearable></el-switch>
					</el-form-item>

				</el-col>
      </el-row>

      <div style="text-align:right;">
        <WtmButton @click="onSubmitProcessDoc"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

        <WtmButton @click="onCloseProcessDoc"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageProcessManagementProcessDocCreate;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { processdocApi } from '/@/api/processmanagement/processdoc';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefProcessDoc = ref();
const stateProcessDoc = reactive({
    vmModel: {
	  Entity:{
        RouteId: null,
        OpId: null,
        OpCode: '',
        ProductId: null,
        FileName: '',
        FileType: '',
        FileDocId: null,
        RemotePc: '',
        RemotePath: '',
        UserName: '',
        Pwd: '',
			 Active:true
      },

	},
    
    AllRoutes: [] as any[],
    AllOps: [] as any[],
});

// 取消
const onCloseProcessDoc = () => {
    closeDialog();
};

const onFileChange = (file: any) =>
{

	stateProcessDoc.vmModel.Entity.FileName = file;
}



// 提交
const onSubmitProcessDoc = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefProcessDoc.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            processdocApi().add(stateProcessDoc.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};

//工艺路线改变时
const  onRouteChange = (routeId:any) =>
{
	if (routeId){

		other.getSelectList(`/api/ProcessManagement/ProcessDoc/GetByProcessIdRouteItems?id=${routeId}`,[],false).then(x=>{stateProcessDoc.AllOps = x});

	}
	else{
		stateProcessDoc.AllOps=[];
		stateProcessDoc.vmModel.Entity.OpId=null;
	}

}


// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/ProcessManagement/ProcessDoc/GetProcessRoutes',[],false).then(x=>{stateProcessDoc.AllRoutes = x});
    other.getSelectList('/api/ProcessManagement/ProcessDoc/GetProcessRouteItems',[],false).then(x=>{stateProcessDoc.AllOps = x});
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

